﻿@model Jabber.Net.Config.JabberConfig
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
    </configSections>
    <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
        <assembly name="Jabber.Net.Server"/>
        <assembly name="agsXMPP"/>

        <namespace name="Jabber.Net.Server"/>
        <namespace name="Jabber.Net.Server.Components"/>
        <namespace name="Jabber.Net.Server.Connections"/>
        <namespace name="Jabber.Net.Server.Handlers"/>
        <namespace name="Jabber.Net.Server.Muc"/>
        <namespace name="Jabber.Net.Server.Sessions"/>
        <namespace name="Jabber.Net.Server.S2C"/>
        <namespace name="Jabber.Net.Server.Storages"/>
        <namespace name="Jabber.Net.Server.Utils"/>

        <container name="Jabber">

            <!-- Jids -->
            <instance name="domain" value="@Model.Domain" type="agsXMPP.Jid, agsXMPP" typeConverter="JidTypeConverter"/>
            <instance name="server" value="^@Model.Domain$" type="agsXMPP.Jid, agsXMPP" typeConverter="JidTypeConverter"/>
            <instance name="user" value=".+@@@Model.Domain.*" type="agsXMPP.Jid, agsXMPP" typeConverter="JidTypeConverter"/>
            @if (Model.MucEnabled)
            {
                <instance name="muc" value="^@Model.MucAddress.@Model.Domain$" type="agsXMPP.Jid, agsXMPP" typeConverter="JidTypeConverter"/>
            }
            <!-- Services -->
            <register type="ServiceInfo" name="Jabber">
                <constructor>
                    <param name="jid" dependencyName="domain"/>
                    <param name="name" value="Jabber.Net"/>
                    <param name="category" value="server"/>
                    <param name="type" value="im"/>
                </constructor>
                <property name="Url" value="http://jabberserver.net"/>
                <property name="Copyrigth" value="© 2011-2012 Ivanoff Nikolay"/>
                <property name="Features">
                    <array>
                        <value value="jabber:client"/>
                        <value value="http://jabber.org/protocol/disco#info"/>
                        <value value="http://jabber.org/protocol/disco#items"/>
                        <value value="vcard-temp"/>
                        <value value="msgoffline"/>
                        <value value="urn:ietf:params:xml:ns:xmpp-streams"/>
                        <value value="urn:ietf:params:xml:ns:xmpp-stanzas"/>
                        <value value="urn:ietf:params:xml:ns:xmpp-sasl"/>
                        <value value="urn:ietf:params:xml:ns:xmpp-sasl#c2s"/>
                        <value value="urn:ietf:params:xml:ns:xmpp-bind"/>
                        <value value="urn:ietf:params:xml:ns:xmpp-session"/>
                        <value value="jabber:iq:last"/>
                        <value value="jabber:iq:version"/>
                        <value value="jabber:iq:roster"/>
                        <value value="urn:xmpp:time"/>
                    </array>
                </property>
            </register>
            @if (Model.MucEnabled)
            {
                <register type="ServiceInfo" name="Muc">
                    <constructor>
                        <param name="jid">
                            <value value="conference.localhost" dependencyName="muc"/>
                        </param>
                        <param name="name" value="Chatroom Service"/>
                        <param name="category" value="conference"/>
                        <param name="type" value="text"/>
                    </constructor>
                    <property name="Url" value="http://jabberserver.net"/>
                    <property name="Copyrigth" value="© 2011-2012 Ivanoff Nikolay"/>
                    <property name="Features">
                        <array>
                            <value value="http://jabber.org/protocol/disco#info"/>
                            <value value="http://jabber.org/protocol/disco#items"/>
                            <value value="http://jabber.org/protocol/muc"/>
                            <value value="vcard-temp"/>
                        </array>
                    </property>
                </register>
            }
            <!-- Listeners -->
            <register type="XmppListenerManager">
                <lifetime type="singleton"/>
                <constructor>
                    <param name="handlerManager" dependencyType="XmppHandlerManager"/>
                </constructor>
                @if (Model.TcpListener != null)
                {
                    <method name="AddListener">
                        <param name="listener" dependencyName="DefaultListener"/>
                    </method>
                }
                @if (Model.ComponentListener != null)
                {
                    <method name="AddListener">
                        <param name="listener" dependencyName="ComponentListener"/>
                    </method>
                }
                @if (Model.BoshListener != null)
                {
                    <method name="AddListener">
                        <param name="listener" dependencyName="BoshListener"/>
                    </method>
                }
            </register>
            @if (Model.TcpListener != null)
            {
                <register type="IXmppListener" mapTo="TcpXmppListener" name="DefaultListener">
                    <lifetime type="singleton"/>
                    <constructor>
                        <param name="listenUri" value="tcp://@Model.IpOrHostName:@Model.TcpListener.Port"/>
                    </constructor>
                </register>
            }
            @if (Model.ComponentListener != null)
            {
                <register type="IXmppListener" mapTo="TcpXmppListener" name="ComponentListener">
                    <lifetime type="singleton"/>
                    <constructor>
                        <param name="listenUri" value="tcp://@Model.IpOrHostName:@Model.ComponentListener.Port"/>
                    </constructor>
                </register>
            }
            @if (Model.BoshListener != null)
            {
                <register type="IXmppListener" mapTo="BoshXmppListener" name="BoshListener">
                    <lifetime type="singleton"/>
                    <constructor>
                        <param name="listenUri" value="http://@Model.IpOrHostName:@(Model.BoshListener.Port)@(Model.BoshListener.Bind)"/>
                    </constructor>
                </register>
            }
            <!-- Sessions -->
            <register type="XmppSessionManager">
                <lifetime type="singleton"/>
            </register>

            <!-- Storages -->
            <register type="XmppStorageManager">
                <lifetime type="singleton"/>
                <method name="AddStorage">
                    <param name="name" value="users"/>
                    <param name="storage" dependencyType="IXmppUserStorage"/>
                </method>
                <method name="AddStorage">
                    <param name="name" value="elements"/>
                    <param name="storage" dependencyType="IXmppElementStorage"/>
                </method>
            </register>

            <register type="IXmppUserStorage" mapTo="XmppUserStorage">
                <lifetime type="singleton"/>
                <constructor>
                    <param name="connectionStringName" value="@Model.UsersConnectionStringName"/>
                    <param name="elements" dependencyType="IXmppElementStorage"/>
                </constructor>
            </register>

            <register type="IXmppElementStorage" mapTo="XmppElementStorage">
                <lifetime type="singleton"/>
                <constructor>
                    <param name="connectionStringName" value="@Model.ElementsConnectionStringName"/>
                </constructor>
            </register>
      
            <!-- Handlers -->
            <register type="XmppHandlerManager">
                <lifetime type="singleton"/>
                <constructor>
                    <param name="sessionManager" dependencyType="XmppSessionManager"/>
                    <param name="resolver" dependencyType="IXmppResolver"/>
                </constructor>
                <method name="RegisterHandler">
                    <param name="handler" dependencyType="ClientStreamHandler"/>
                </method>
                @if (Model.TcpListener != null && Model.TcpListener.EnableTls)
                {
                    <method name="RegisterHandler">
                        <param name="handler" dependencyType="TlsHandler"/>
                    </method>
                }
                <method name="RegisterHandler">
                    <param name="handler" dependencyType="AuthDigestMD5Handler"/>
                </method>

                <method name="RegisterHandler">
                    <param name="jid" dependencyName="server"/>
                    <param name="handler">
                        <dependency type="ServiceDiscoInfoHandler" name="JabberDiscoInfoHandler"/>
                    </param>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="server"/>
                    <param name="handler">
                        <dependency type="ServiceDiscoItemsHandler" name="JabberDiscoItemsHandler"/>
                    </param>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="server"/>
                    <param name="handler">
                        <dependency type="ServiceVCardHandler" name="JabberVCardHandler"/>
                    </param>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="server"/>
                    <param name="handler" dependencyType="ServiceLastHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="server"/>
                    <param name="handler" dependencyType="ServiceVersionHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="server"/>
                    <param name="handler" dependencyType="RegisterHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="server"/>
                    <param name="handler" dependencyType="ServiceTimeHandler"/>
                </method>

                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="BindHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="SessionHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="PrivateHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="ClientVCardHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="ClientRosterHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="PresenceSubscribeHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="PresenceSubscribedHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="PresenceUnsubscribeHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="PresenceUnsubscribedHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="PresenceAvailableHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="PresenceUnavailableHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="ClientMessageHandler"/>
                </method>
                <method name="RegisterHandler">
                    <param name="jid" dependencyName="user"/>
                    <param name="handler" dependencyType="ClientLastHandler"/>
                </method>
                @if (Model.MucEnabled)
                {
                    <method name="RegisterHandler">
                        <param name="jid" dependencyName="muc"/>
                        <param name="handler">
                            <dependency name="MucDiscoInfoHandler" type="ServiceDiscoInfoHandler"/>
                        </param>
                    </method>
                    <method name="RegisterHandler">
                        <param name="jid" dependencyName="muc"/>
                        <param name="handler">
                            <dependency name="MucVCardHandler" type="ServiceVCardHandler"/>
                        </param>
                    </method>
                    <method name="RegisterHandler">
                        <param name="jid" dependencyName="muc"/>
                        <param name="handler" dependencyType="MucDiscoItemsHandler"/>
                    </method>
                }
                @if (Model.BoshListener != null)
                {
                    <method name="RegisterHandler">
                        <param name="handler" dependencyType="BoshHandler"/>
                    </method>
                }

            </register>

            <register type="ClientStreamHandler">
                <constructor>
                    <param name="domain" dependencyName="domain"/>
                </constructor>
            </register>
            @if (Model.TcpListener != null && Model.TcpListener.EnableTls)
            {
                <register type="TlsHandler">
                    <constructor>
                        <param name="certificatefile" value="@Model.TcpListener.CertificatePath"/>
                    </constructor>
                </register>
            }
            <register type="AuthDigestMD5Handler"/>
            <register type="BindHandler"/>
            <register type="SessionHandler"/>
            <register type="ServiceDiscoInfoHandler" name="JabberDiscoInfoHandler">
                <constructor>
                    <param name="serviceInfo" dependencyName="Jabber"/>
                </constructor>
            </register>
            <register type="ServiceDiscoItemsHandler" name="JabberDiscoItemsHandler">
                <constructor>
                    <param name="items">
                        <array>
                            @if (Model.MucEnabled)
                            {
                                <dependency name="Muc"/>
                            }
                        </array>
                    </param>
                </constructor>
            </register>
            <register type="ServiceVCardHandler" name="JabberVCardHandler">
                <constructor>
                    <param name="serviceInfo" dependencyName="Jabber"/>
                </constructor>
            </register>
            <register type="ServiceLastHandler"/>
            <register type="ServiceVersionHandler">
                <constructor>
                    <param name="serviceInfo" dependencyName="Jabber"/>
                </constructor>
            </register>
            <register type="PrivateHandler"/>
            <register type="RegisterHandler"/>
            <register type="ClientVCardHandler"/>
            <register type="ClientRosterHandler"/>
            <register type="ClientMessageHandler"/>
            <register type="ClientLastHandler"/>
            <register type="PresenceSubscribeHandler"/>
            <register type="PresenceSubscribedHandler"/>
            <register type="PresenceUnsubscribeHandler"/>
            <register type="PresenceUnsubscribedHandler"/>
            <register type="PresenceAvailableHandler"/>
            <register type="PresenceUnavailableHandler"/>
            <register type="ServiceTimeHandler"/>
            @if (Model.ComponentListener != null)
            {
                <register type="ComponentHandler">
                    <constructor>
                        <param name="domain" dependencyName="muc"/><!--TODO: Change to component jid-->
                        <param name="secret" value="@Model.ComponentListener.Secret"/>
                    </constructor>
                </register>
            }
            @if (Model.BoshListener != null)
            {
                <register type="BoshHandler"/>
            }
            @if (Model.MucEnabled)
            {
                <register type="ServiceDiscoInfoHandler" name="MucDiscoInfoHandler">
                    <constructor>
                        <param name="serviceInfo" dependencyName="Muc"/>
                    </constructor>
                </register>
                <register type="ServiceVCardHandler" name="MucVCardHandler">
                    <constructor>
                        <param name="serviceInfo" dependencyName="Muc"/>
                    </constructor>
                </register>
                <register type="MucDiscoItemsHandler"/>
            }
        </container>
    </unity>
</configuration>